﻿using System;
using UltimatePlugin.Db;
using UltimatePlugin.UI;
using Zeta;
using Zeta.Common.Plugins;
using Zeta.CommonBot;

namespace UltimatePlugin
{
    public class UltimatePlugin : IPlugin
    {
        public Version Version
        {
            get
            {
                return new Version(0, 1, 0, 0);
            }
        }

        public string Author
        {
            get
            {
                return "CrazyHT";
            }
        }

        public string Description
        {
            get
            {
                return string.Format("Ultimate Plugin version {0}", Version);
            }
        }

        public string Name
        {
            get
            {
                return "Ultimate Plugin";
            }
        }

        public System.Windows.Window DisplayWindow
        {
            get
            {
                return UIManager.GetDisplayWindow();
            }
        }

        public void OnDisabled()
        {
            BotMain.OnStart -= OnBotStart;
            BotMain.OnStop -= OnBotStop;
            if (ZetaDia.IsInGame)
            {
                OnBotStop(BotMain.CurrentBot);
            }
        }

        public void OnEnabled()
        {
            BotMain.OnStart += OnBotStart;
            BotMain.OnStop += OnBotStop;
            if (ZetaDia.IsInGame)
            {
                OnBotStart(BotMain.CurrentBot);
            }
        }

        public void OnInitialize()
        {
            CheckInstall();
        }

        public void OnPulse()
        {
            // Do Nothing 
        }

        public void OnShutdown()
        {
        }

        private void OnBotStop(IBot bot)
        {
            TreeHookManager.ReplaceHook(false);
            GameEvents.OnItemIdentificationRequest -= ActionHelper.IdentificationRequestAction;
        }

        private void OnBotStart(IBot bot)
        {
            TreeHookManager.ReplaceHook(true);
            GameEvents.OnItemIdentificationRequest += ActionHelper.IdentificationRequestAction;
        }

        private void CheckInstall()
        {
        }

        public bool Equals(IPlugin other)
        {
            return string.Format("{0} - {1}", Name, Version) == string.Format("{0} - {1}", other.Name, other.Version);
        }
    }
}
